<?php

namespace addons\Archives\common\models;

use Yii;
use yii\db\ActiveQuery;

/**
 * This is the model class for table "{{%addon_oa_study}}".
 *
 * @property int $id 编号
 * @property int $cate_id 分类
 * @property string $title 标题
 * @property string $content 内容
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 */
class Archives extends \common\models\base\BaseModel
{


    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%addon_archives}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['title', 'cate_id',  'send_time'], 'required'],
            [['merchant_id','cate_id', 'created_at', 'updated_at', 'status'], 'integer'],
            [['title','serial', 'cabinet', 'box'], 'string', 'max' => 32],
            [['send_time','covers'], 'safe'],
            [['serial'], 'unique', 'filter' => function (ActiveQuery $query) {
                return $query->all();
            }],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => '标题',
            'cate_id' => '分类',
            'serial' => '档案编号',
            'cabinet' => '文件柜编号',
            'box' => '文件盒编号',
            'send_time' => '发文时间',
            'covers' => '图片',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }
    public function getCate()
    {
        return $this->hasOne(ArchivesCate::class, ['id' => 'cate_id']);
    }
    public function beforeSave($insert)
    {
        $this->merchant_id = Yii::$app->user->identity->merchant_id;
        return parent::beforeSave($insert);
    }


}
